//毕业证分享
app.controller('ShareGrade', function($scope, $http, common, wechat){
    //初始化
    $scope.init_start   = function(){
        $scope.get  = httpToObject(base64decode(getUrlParam('param')));
        //微信分享设置
        wechat.wxConfig(function(){
            wx.showMenuItems({
                menuList    : ['menuItem:share:appMessage', 'menuItem:share:timeline']
            });
            var title   = '正心源毕业证';
            var desc    = '正心源课程毕业证';
            var url     = window.location.href;
            var callback     = function(result){
                if(result){
                    //记录分享动作
                    common.getUserInfo(function(user){
                        if(user){
                            var param   = {
                                'user_id'   : user.id,
                                'course_id' : $scope.get.course_id
                            }
                            var url     = config.prefix_url+'/Share/shareSuccess?'+
                                '&param=' + base64encode(objectToHttp(param));
                            $http.get(url).success(function(info){
                                console.log(info);
                            });
                        }
                    });
                }
            }
            wechat.wxShareFriend(title, desc, url, false, callback);
            wechat.wxShareTimeLine(title, url, false, callback);
        });
    }

    //更换主题
    $scope.change_theme     = function(){
        $scope.get.theme_id     = parseInt($scope.get.theme_id) + 1;
        if($scope.get.theme_id > 3) $scope.get.theme_id = 1;

        var param   = base64encode(objectToHttp($scope.get));
        var url     = 'index.html?'+'&param='+param+'&#/Share/graduate';

        //本地存储theme_id
        D('share_graduate_theme_id', $scope.get.theme_id);

        window.open(url, '_self');
    }

    $scope.init_start();
    $scope.shareImg     = config.prefix_url+'/Share/courseGraduatePNG?param='+getUrlParam('param');
});

//课程分享
app.controller('ShareCourse', function($scope, $http, wechat, common){
    //初始化
    $scope.init_start   = function(){
        $scope.get  = httpToObject(base64decode(getUrlParam('param')));
        //微信分享设置
        wechat.wxConfig(function(){
            wx.showMenuItems({
                menuList    : ['menuItem:share:appMessage', 'menuItem:share:timeline']
            });
            var title   = '正心源课程';
            var desc    = '发现好课程与你分享！';
            var url     = window.location.href;
            var callback     = function(result){
                if(result){
                    //记录分享动作
                    common.getUserInfo(function(user){
                        if(user){
                            var param   = {
                                'user_id'   : user.id,
                                'course_id' : $scope.get.course_id
                            }
                            var url     = config.prefix_url+'/Share/shareSuccess?'+
                                '&param=' + base64encode(objectToHttp(param));
                            $http.get(url).success(function(info){
                                console.log(info);
                            });
                        }
                    });
                }
            }
            wechat.wxShareFriend(title, desc, url, false, callback);
            wechat.wxShareTimeLine(title, url, false, callback);
        });
    }
    
    //更换主题
    $scope.change_theme     = function(){
        $scope.get.theme_id     = parseInt($scope.get.theme_id) + 1;
        if($scope.get.theme_id > 5) $scope.get.theme_id = 1;

        var param   = base64encode(objectToHttp($scope.get));
        var url     = 'index.html?'+'&param='+param+'&#/Share/course';

        //本地存储theme_id
        D('share_course_theme_id', $scope.get.theme_id);

        window.open(url, '_self');
    }

    $scope.init_start();
    $scope.shareImg     = config.prefix_url+'/Share/courseSharePNG?param='+getUrlParam('param');
});

//主题相册分享
app.controller('ActivityPicture', function($scope, $http, $timeout, wechat, common){
    $scope.param     = common.getUrlParam('param');
    if(!$scope.param){
        common.doAlert('参数获取失败!');
        return false;
    }

    //初始化js
    $scope.init_js  = function(){
        common.setTitle('主题相册');
        //微信分享设置
        wechat.wxConfig(function(){
            wx.showMenuItems({
                menuList    : ['menuItem:share:appMessage', 'menuItem:share:timeline']
            });
            var title   = '正心源活动分享';
            var desc    = '主题活动相册分享！';
            var url     = window.location.href;
            var callback     = function(result){
                console.log(result);
            }
            wechat.wxShareFriend(title, desc, url, false, callback);
            wechat.wxShareTimeLine(title, url, false, callback);
        });
    }

    //加载数据
    $scope.load_data    = function(){
        var url     = config.prefix_url + '/Share/activityPicture?param='+$scope.param;
        $http.get(url).success(function(info){
            console.log(info);
            if(info.code != 1){
                common.dealError(info);
                return false;
            }
            $scope.list     = info.data.list;

            $timeout(function(){
                $('.am-slider').flexslider();
            }, 500);
        })
    }

    $scope.init_js();
    $scope.load_data();
})
